import { _decorator, instantiate, Node, Prefab } from "cc";
import { BaseSceneManager } from "./base-scene-manager";
import { ItemType } from "../model";
import { BackPackManager } from "../back-pack-manager";
const { ccclass, property } = _decorator;

@ccclass("H2SceneManager")
export class H2SceneManager extends BaseSceneManager {
  @property({ type: Node, tooltip: "钥匙占位" })
  public keyPlaceholder: Node = null;

  @property({ type: Prefab, tooltip: "钥匙预制体" })
  public keyPrefab: Prefab = null;

  render() {
    this.items.removeAllChildren();

    const isKeyInScene = BackPackManager.Instance.isItemInScene(ItemType.Key);
    if (isKeyInScene) {
      const key = instantiate(this.keyPrefab);
      this.items.addChild(key);
      key.setPosition(this.keyPlaceholder.position);
    }
  }
}
